package testJdk.lambda.testPredicate;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
 * @version 1.0.0
 * Created by cyd on 2021-12-15 11:31:38
 * @ClassName : learn_jdk.lambda.testPredicate.Predicateutil
 * @Description : 类描述
 */
public class PredicateUtil {
    /**
     * 断言型接口
     *
     * @param list  被判断的参数
     * @param logic 判断的逻辑
     * @return 结果
     */
    public static List<Integer> filter(List<Integer> list, Predicate<Integer> logic) {
        List<Integer> newList = new ArrayList<>();
        for (Integer s : list) {
            // 判断的逻辑,返回布尔值
            if (logic.test(s)) {
                newList.add(s);
            }
        }
        return newList;
    }
}
